import numpy as np
import matplotlib.pyplot as plt

np.set_printoptions(suppress=True, linewidth=999)
plt.rc('font', family='Times New Roman', weight='normal', size=18)

for i in range(1, 31):
    if i == 2:
        continue

    callso = np.loadtxt(f'./callso_func{i}_d100.txt')
    callso_gBest = callso[:, 0]
    callso_acc = callso[:, 1]

    casdlso = np.loadtxt(f'./casdlso_func{i}_d100.txt')
    casdlso_gBest = casdlso[:, 0]
    casdlso_acc = casdlso[:, 1]
    # casdlso_loss = casdlso[:, 2]
    # casdlso_updated = casdlso[:, 3]

    plt.figure(figsize=(10, 4))
    plt.clf()
    plt.subplot(1, 2, 1)
    plt.plot(range(len(callso_gBest)), callso_gBest, label='CA-LLSO')
    plt.plot(range(len(casdlso_gBest)), casdlso_gBest, label='CA-SDLSO')
    plt.legend()
    plt.title(f'fitness of CEC2017 func{i} d100')
    plt.subplot(1, 2, 2)
    plt.plot(range(len(callso_acc)), callso_acc, label='CA-LLSO')
    plt.plot(range(len(casdlso_acc)), casdlso_acc, label='CA-SDLSO')
    plt.legend()
    plt.title(f'accuracy')

    # plt.subplot(2, 2, 3)
    # plt.plot(range(len(self.loss)), self.loss)
    # plt.title(f'loss: {self.loss[-1]}')
    # plt.subplot(2, 2, 4)
    # plt.plot(range(len(self.updated)), self.updated)
    # plt.title(f'updated: {self.updated[-1]}')

    plt.tight_layout()
    # plt.show()
    plt.savefig(f'{i}.png', dpi=600)
